<?php
/**
 * Created by PhpStorm.
 * User: HLG
 * Date: 2018/12/10
 * Time: 9:31
 */
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Session;
use app\admin\model\AdminModel;
class BaseController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->checkLogin();
        //获取当前控制器
        $controller = request()->controller();
        //获取当前方法名
        $action = request()->action();
        //生成标识符
        $name=$controller."_".$action;
        $AdminModel=new AdminModel();
        //利用管理员id和标识符判断与无此数据
        $bool=$AdminModel->isadmin(Session::get("admin_id"),$name);
        $names=["Index_index"];
        if(Session::get('isadmin')==1||in_array($name,$names)) {
            return 1;
        }elseif(!$bool){
            echo "您没有此权限！";
            die();
        }else{
            return 0;
        }
    }

    public function checkLogin()
    {
        $admin_id = session('admin_id');
        if(empty($admin_id)){
            return $this->error('请先登录','login/doLogin');
        }
    }
}